package interview.CooperateSystem.common.handler.impl;


import interview.CooperateSystem.common.CommonHandleContext;
import interview.CooperateSystem.common.CommonMessage;
import interview.CooperateSystem.common.entity.Message;
import interview.CooperateSystem.common.handler.Handler;

/**
 * Created by angela on 6/6/2014.
 */
public abstract class HandlerTemplate<M extends CommonMessage> implements Handler<M> {
    @Override
    public void reveiveMessage(Message message) {
        Handler<M> handle = getHandlerFromContext(message);
        M specialMessage = handle.translateMessage(message);
        processMessage(specialMessage);
    }

    public Handler getHandlerFromContext(Message message){
        return CommonHandleContext.getInstance().getHandlerFromContext(message);
    }
}
